#ifndef RENDERAREA_H
#define RENDERAREA_H

#include <QBrush>
#include <QPen>
#include <QPixmap>
#include <QWidget>

#include <QPaintEvent>
#include <QPaintEngine>
#include <QTime>

#include "Light.h"
#include "model.h"
#include "Camera.h"
#include "renderer.h"
#include "LineRenderer.h"
#include "SimpleRenderer.h"
#include "SimpleColoredRenderer.h"
#include "NearestTexturedRenderer.h"
#include "LinearTexturedRenderer.h"
#include "PerspectiveLinearRenderer.h"
#include "PerspectiveNearestRenderer.h"

#include <cmath>

class RenderArea : public QWidget
{
      Q_OBJECT

   public:
      RenderArea( QWidget *parent = 0 );
      ~RenderArea();

      QSize minimumSizeHint() const;
      QSize sizeHint() const;

   public slots:
      void setPen(const QPen &pen);
      void setBrush(const QBrush &brush);
      void setAntialiased(bool antialiased);
      void setTransformed(bool transformed);
      void setRenderer( int renderer ); /// @param renderer renderer type like in GUI
      void setDemo( int demo );
      
      void setLightEnabled( bool enable );
      void setAmbientLightEnabled( bool enable );
      void setLight1Enabled( bool enable );
      void setLight2Enabled( bool enable );
      void setLight3Enabled( bool enable );
      
      void disableAmbientLight();
      void disableLight1();
      void disableLight2();
      void disableLight3();
      
      void setAmbientRed( int c );
      void setAmbientGreen( int c );
      void setAmbientBlue( int c );
      
      void setLight1Red( int c );
      void setLight1Green( int c );
      void setLight1Blue( int c );
      
      void setLight2Red( int c );
      void setLight2Green( int c );
      void setLight2Blue( int c );
      
      void setLight3Red( int c );
      void setLight3Green( int c );
      void setLight3Blue( int c );
      
      void slotUpdateFps();
      
      
   signals:
      void setHiddenSurfaceRemovalEnabled( bool enable );
      void updateFps( int fps );
      void shouldUpdate();

   protected:
      void paintEvent(QPaintEvent *event);
      void resizeEvent( QResizeEvent *event );
      void keyPressEvent( QKeyEvent *event );
      void mouseMoveEvent( QMouseEvent *event );
      void mousePressEvent( QMouseEvent *event );

   private:
      QPen m_pen;
      QBrush m_brush;
      bool m_antialiased;
      bool m_transformed;
      QImage *m_image;
      
      QTime m_frameTime;
      
      QTime m_fpsTimer;
      int m_frameCounter;
      
      RendererVertex *m_v;
      
      int m_demo;
      
      int m_oldMouseX;
      int m_oldMouseY;
      
      Light m_ambientLight;
      Light m_light1;
      Light m_light2;
      Light m_light3;
      
      bool m_ambientLightEnabled;
      bool m_light1Enabled;
      bool m_light2Enabled;
      bool m_light3Enabled;
      
      Renderer *m_renderer;
      
      Camera m_camera;
      
      Model m_cube;
      Model m_teapot;
      Model m_car;
      Model m_model;
      
      LineRenderer m_lineRenderer;
      SimpleRenderer m_fillRenderer;
      SimpleColoredRenderer m_coloredRenderer;
      NearestTexturedRenderer m_texturedNearestRenderer;
      LinearTexturedRenderer m_texturedLinearRenderer;
      PerspectiveLinearRenderer m_perspectiveLinearRenderer;
      PerspectiveNearestRenderer m_perspectiveNearestRenderer;
};

#endif 
